package cn.jlonely.xyhx.admin.controller;

import cn.jlonely.xyhx.pojo.Ranking;
import cn.jlonely.xyhx.admin.service.RankingService;
import cn.jlonely.xyhx.pojo.vo.CommentPageVo;
import cn.jlonely.xyhx.utils.PageResult;
import cn.jlonely.xyhx.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController("adminRankingController")
@RequestMapping("/admin")
public class RankingController {

    /**
     * 查找榜单
     */
    @Autowired
    private RankingService rankingService;

    @GetMapping("/getRankingInfoAll")
    public Result getRankingInfo(String topic, Integer id) {
        List<Ranking> ranking = rankingService.getRankingInfoAll(topic, id);
        return Result.success(ranking);
    }

    /**
     * 创建榜单
     */
    @PostMapping("/createRanking")
    public Result createRanking(@RequestBody Ranking ranking) {
        rankingService.createRanking(ranking);
        return Result.success();
    }

    /**
     * 删除榜单
     */
    @DeleteMapping("/deleteRanking")
    public Result deleteRanking(@RequestParam("id") Integer id) {
        rankingService.deleteRanking(id);
        return Result.success();
    }

    /**
     * 修改榜单
     */
    @PutMapping("/updateRanking")
    public Result updateRanking(@RequestBody Ranking ranking) {
        rankingService.updateRanking(ranking);
        return Result.success();
    }

    /**
     * 获取评论分页
     */
    @GetMapping("/getCommentsPage")
    public Result getCommentsPage(@RequestParam("page") Integer page, @RequestParam("pageSize") Integer pageSize) {
        PageResult<CommentPageVo> pageResult = rankingService.getCommentsPage(page, pageSize);
        return Result.success(pageResult);
    }

    /**
     * 修改评论状态
     * @param commentId
     * @param status
     * @return
     */
    @PutMapping("/updateCommentsStatus")
    public Result updateCommentsStatus(@RequestParam("commentId") Integer commentId,@RequestParam("status") Integer status) {
        rankingService.updateCommentsStatus(commentId,status);
        return Result.success();
    }
    /**
     * 删除评论
     */
    @DeleteMapping("/deleteComments")
    public Result deleteComments(@RequestParam("commentId") Integer commentId) {
        rankingService.deleteComments(commentId);
        return Result.success();
    }

}
